home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / atom / __init__.pyc (.txt) next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  48.5 KB  |  1,502 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Contains classes representing Atom elements.
  5.  
  6.   Module objective: provide data classes for Atom constructs. These classes hide
  7.   the XML-ness of Atom and provide a set of native Python classes to interact 
  8.   with.
  9.  
  10.   Conversions to and from XML should only be necessary when the Atom classes
  11.   "touch the wire" and are sent over HTTP. For this reason this module 
  12.   provides  methods and functions to convert Atom classes to and from strings.
  13.  
  14.   For more information on the Atom data model, see RFC 4287 
  15.   (http://www.ietf.org/rfc/rfc4287.txt)
  16.  
  17.   AtomBase: A foundation class on which Atom classes are built. It 
  18.       handles the parsing of attributes and children which are common to all
  19.       Atom classes. By default, the AtomBase class translates all XML child 
  20.       nodes into ExtensionElements.
  21.  
  22.   ExtensionElement: Atom allows Atom objects to contain XML which is not part 
  23.       of the Atom specification, these are called extension elements. If a 
  24.       classes parser encounters an unexpected XML construct, it is translated
  25.       into an ExtensionElement instance. ExtensionElement is designed to fully
  26.       capture the information in the XML. Child nodes in an XML extension are
  27.       turned into ExtensionElements as well.
  28. '''
  29. __author__ = 'api.jscudder (Jeffrey Scudder)'
  30.  
  31. try:
  32.     from xml.etree import cElementTree as ElementTree
  33. except ImportError:
  34.     
  35.     try:
  36.         import cElementTree as ElementTree
  37.     except ImportError:
  38.         
  39.         try:
  40.             from xml.etree import ElementTree
  41.         except ImportError:
  42.             from elementtree import ElementTree
  43.         except:
  44.             None<EXCEPTION MATCH>ImportError
  45.         
  46.  
  47.         None<EXCEPTION MATCH>ImportError
  48.     
  49.  
  50.     None<EXCEPTION MATCH>ImportError
  51.  
  52. ATOM_NAMESPACE = 'http://www.w3.org/2005/Atom'
  53. ELEMENT_TEMPLATE = '{http://www.w3.org/2005/Atom}%s'
  54. APP_NAMESPACE = 'http://purl.org/atom/app#'
  55. APP_TEMPLATE = '{http://purl.org/atom/app#}%s'
  56. XML_STRING_ENCODING = 'utf-8'
  57. MEMBER_STRING_ENCODING = 'utf-8'
  58.  
  59. def CreateClassFromXMLString(target_class, xml_string, string_encoding = None):
  60.     '''Creates an instance of the target class from the string contents.
  61.   
  62.   Args:
  63.     target_class: class The class which will be instantiated and populated
  64.         with the contents of the XML. This class must have a _tag and a
  65.         _namespace class variable.
  66.     xml_string: str A string which contains valid XML. The root element
  67.         of the XML string should match the tag and namespace of the desired
  68.         class.
  69.     string_encoding: str The character encoding which the xml_string should
  70.         be converted to before it is interpreted and translated into 
  71.         objects. The default is None in which case the string encoding
  72.         is not changed.
  73.  
  74.   Returns:
  75.     An instance of the target class with members assigned according to the
  76.     contents of the XML - or None if the root XML tag and namespace did not
  77.     match those of the target class.
  78.   '''
  79.     if not string_encoding:
  80.         pass
  81.     encoding = XML_STRING_ENCODING
  82.     if encoding and isinstance(xml_string, unicode):
  83.         xml_string = xml_string.encode(encoding)
  84.     
  85.     tree = ElementTree.fromstring(xml_string)
  86.     return _CreateClassFromElementTree(target_class, tree)
  87.  
  88.  
  89. def _CreateClassFromElementTree(target_class, tree, namespace = None, tag = None):
  90.     """Instantiates the class and populates members according to the tree.
  91.  
  92.   Note: Only use this function with classes that have _namespace and _tag
  93.   class members.
  94.  
  95.   Args:
  96.     target_class: class The class which will be instantiated and populated
  97.         with the contents of the XML.
  98.     tree: ElementTree An element tree whose contents will be converted into
  99.         members of the new target_class instance.
  100.     namespace: str (optional) The namespace which the XML tree's root node must
  101.         match. If omitted, the namespace defaults to the _namespace of the 
  102.         target class.
  103.     tag: str (optional) The tag which the XML tree's root node must match. If
  104.         omitted, the tag defaults to the _tag class member of the target 
  105.         class.
  106.  
  107.     Returns:
  108.       An instance of the target class - or None if the tag and namespace of 
  109.       the XML tree's root node did not match the desired namespace and tag.
  110.   """
  111.     if namespace is None:
  112.         namespace = target_class._namespace
  113.     
  114.     if tag is None:
  115.         tag = target_class._tag
  116.     
  117.     if tree.tag == '{%s}%s' % (namespace, tag):
  118.         target = target_class()
  119.         target._HarvestElementTree(tree)
  120.         return target
  121.     return None
  122.  
  123.  
  124. class ExtensionContainer(object):
  125.     
  126.     def __init__(self, extension_elements = None, extension_attributes = None, text = None):
  127.         if not extension_elements:
  128.             pass
  129.         self.extension_elements = []
  130.         if not extension_attributes:
  131.             pass
  132.         self.extension_attributes = { }
  133.         self.text = text
  134.  
  135.     
  136.     def _HarvestElementTree(self, tree):
  137.         for child in tree:
  138.             self._ConvertElementTreeToMember(child)
  139.         
  140.         for attribute, value in tree.attrib.iteritems():
  141.             self._ConvertElementAttributeToMember(attribute, value)
  142.         
  143.         if tree.text:
  144.             if MEMBER_STRING_ENCODING is unicode:
  145.                 self.text = tree.text
  146.             else:
  147.                 self.text = tree.text.encode(MEMBER_STRING_ENCODING)
  148.         
  149.  
  150.     
  151.     def _ConvertElementTreeToMember(self, child_tree, current_class = None):
  152.         self.extension_elements.append(_ExtensionElementFromElementTree(child_tree))
  153.  
  154.     
  155.     def _ConvertElementAttributeToMember(self, attribute, value):
  156.         if value:
  157.             if MEMBER_STRING_ENCODING is unicode:
  158.                 self.extension_attributes[attribute] = value
  159.             else:
  160.                 self.extension_attributes[attribute] = value.encode(MEMBER_STRING_ENCODING)
  161.         
  162.  
  163.     
  164.     def _AddMembersToElementTree(self, tree):
  165.         for child in self.extension_elements:
  166.             child._BecomeChildElement(tree)
  167.         
  168.         for attribute, value in self.extension_attributes.iteritems():
  169.             if value:
  170.                 if isinstance(value, unicode) or MEMBER_STRING_ENCODING is unicode:
  171.                     tree.attrib[attribute] = value
  172.                 else:
  173.                     tree.attrib[attribute] = value.decode(MEMBER_STRING_ENCODING)
  174.             MEMBER_STRING_ENCODING is unicode
  175.         
  176.         if self.text:
  177.             if isinstance(self.text, unicode) or MEMBER_STRING_ENCODING is unicode:
  178.                 tree.text = self.text
  179.             else:
  180.                 tree.text = self.text.decode(MEMBER_STRING_ENCODING)
  181.         
  182.  
  183.     
  184.     def FindExtensions(self, tag = None, namespace = None):
  185.         '''Searches extension elements for child nodes with the desired name.
  186.  
  187.     Returns a list of extension elements within this object whose tag
  188.     and/or namespace match those passed in. To find all extensions in
  189.     a particular namespace, specify the namespace but not the tag name.
  190.     If you specify only the tag, the result list may contain extension
  191.     elements in multiple namespaces.
  192.  
  193.     Args:
  194.       tag: str (optional) The desired tag
  195.       namespace: str (optional) The desired namespace
  196.  
  197.     Returns:
  198.       A list of elements whose tag and/or namespace match the parameters
  199.       values
  200.     '''
  201.         results = []
  202.         if tag and namespace:
  203.             for element in self.extension_elements:
  204.                 if element.tag == tag and element.namespace == namespace:
  205.                     results.append(element)
  206.                     continue
  207.             
  208.         elif tag and not namespace:
  209.             for element in self.extension_elements:
  210.                 if element.tag == tag:
  211.                     results.append(element)
  212.                     continue
  213.             
  214.         elif namespace and not tag:
  215.             for element in self.extension_elements:
  216.                 if element.namespace == namespace:
  217.                     results.append(element)
  218.                     continue
  219.             
  220.         else:
  221.             for element in self.extension_elements:
  222.                 results.append(element)
  223.             
  224.         return results
  225.  
  226.  
  227.  
  228. class AtomBase(ExtensionContainer):
  229.     _children = { }
  230.     _attributes = { }
  231.     
  232.     def __init__(self, extension_elements = None, extension_attributes = None, text = None):
  233.         if not extension_elements:
  234.             pass
  235.         self.extension_elements = []
  236.         if not extension_attributes:
  237.             pass
  238.         self.extension_attributes = { }
  239.         self.text = text
  240.  
  241.     
  242.     def _ConvertElementTreeToMember(self, child_tree):
  243.         if self.__class__._children.has_key(child_tree.tag):
  244.             member_name = self.__class__._children[child_tree.tag][0]
  245.             member_class = self.__class__._children[child_tree.tag][1]
  246.             if isinstance(member_class, list):
  247.                 if getattr(self, member_name) is None:
  248.                     setattr(self, member_name, [])
  249.                 
  250.                 getattr(self, member_name).append(_CreateClassFromElementTree(member_class[0], child_tree))
  251.             else:
  252.                 setattr(self, member_name, _CreateClassFromElementTree(member_class, child_tree))
  253.         else:
  254.             ExtensionContainer._ConvertElementTreeToMember(self, child_tree)
  255.  
  256.     
  257.     def _ConvertElementAttributeToMember(self, attribute, value):
  258.         if self.__class__._attributes.has_key(attribute):
  259.             if value:
  260.                 if MEMBER_STRING_ENCODING is unicode:
  261.                     setattr(self, self.__class__._attributes[attribute], value)
  262.                 else:
  263.                     setattr(self, self.__class__._attributes[attribute], value.encode(MEMBER_STRING_ENCODING))
  264.             
  265.         else:
  266.             ExtensionContainer._ConvertElementAttributeToMember(self, attribute, value)
  267.  
  268.     
  269.     def _AddMembersToElementTree(self, tree):
  270.         member_node_names = [ values[0] for tag, values in self.__class__._children.iteritems() ]
  271.         for member_name in member_node_names:
  272.             member = getattr(self, member_name)
  273.             if member is None:
  274.                 continue
  275.             []
  276.             if isinstance(member, list):
  277.                 for instance in member:
  278.                     instance._BecomeChildElement(tree)
  279.                 
  280.             []
  281.             member._BecomeChildElement(tree)
  282.         
  283.         for xml_attribute, member_name in self.__class__._attributes.iteritems():
  284.             member = getattr(self, member_name)
  285.             if member is not None:
  286.                 if isinstance(member, unicode) or MEMBER_STRING_ENCODING is unicode:
  287.                     tree.attrib[xml_attribute] = member
  288.                 else:
  289.                     tree.attrib[xml_attribute] = member.decode(MEMBER_STRING_ENCODING)
  290.             MEMBER_STRING_ENCODING is unicode
  291.         
  292.         ExtensionContainer._AddMembersToElementTree(self, tree)
  293.  
  294.     
  295.     def _BecomeChildElement(self, tree):
  296.         '''
  297.  
  298.     Note: Only for use with classes that have a _tag and _namespace class 
  299.     member. It is in AtomBase so that it can be inherited but it should
  300.     not be called on instances of AtomBase.
  301.     
  302.     '''
  303.         new_child = ElementTree.Element('')
  304.         tree.append(new_child)
  305.         new_child.tag = '{%s}%s' % (self.__class__._namespace, self.__class__._tag)
  306.         self._AddMembersToElementTree(new_child)
  307.  
  308.     
  309.     def _ToElementTree(self):
  310.         '''
  311.  
  312.     Note, this method is designed to be used only with classes that have a 
  313.     _tag and _namespace. It is placed in AtomBase for inheritance but should
  314.     not be called on this class.
  315.  
  316.     '''
  317.         new_tree = ElementTree.Element('{%s}%s' % (self.__class__._namespace, self.__class__._tag))
  318.         self._AddMembersToElementTree(new_tree)
  319.         return new_tree
  320.  
  321.     
  322.     def ToString(self, string_encoding = 'UTF-8'):
  323.         '''Converts the Atom object to a string containing XML.'''
  324.         return ElementTree.tostring(self._ToElementTree(), encoding = string_encoding)
  325.  
  326.     
  327.     def __str__(self):
  328.         return self.ToString()
  329.  
  330.  
  331.  
  332. class Name(AtomBase):
  333.     '''The atom:name element'''
  334.     _tag = 'name'
  335.     _namespace = ATOM_NAMESPACE
  336.     _children = AtomBase._children.copy()
  337.     _attributes = AtomBase._attributes.copy()
  338.     
  339.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  340.         '''Constructor for Name
  341.  
  342.     Args:
  343.       text: str The text data in the this element
  344.       extension_elements: list A  list of ExtensionElement instances
  345.       extension_attributes: dict A dictionary of attribute value string pairs
  346.     '''
  347.         self.text = text
  348.         if not extension_elements:
  349.             pass
  350.         self.extension_elements = []
  351.         if not extension_attributes:
  352.             pass
  353.         self.extension_attributes = { }
  354.  
  355.  
  356.  
  357. def NameFromString(xml_string):
  358.     return CreateClassFromXMLString(Name, xml_string)
  359.  
  360.  
  361. class Email(AtomBase):
  362.     '''The atom:email element'''
  363.     _tag = 'email'
  364.     _namespace = ATOM_NAMESPACE
  365.     _children = AtomBase._children.copy()
  366.     _attributes = AtomBase._attributes.copy()
  367.     
  368.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  369.         '''Constructor for Email
  370.  
  371.     Args:
  372.       extension_elements: list A  list of ExtensionElement instances
  373.       extension_attributes: dict A dictionary of attribute value string pairs
  374.       text: str The text data in the this element
  375.     '''
  376.         self.text = text
  377.         if not extension_elements:
  378.             pass
  379.         self.extension_elements = []
  380.         if not extension_attributes:
  381.             pass
  382.         self.extension_attributes = { }
  383.  
  384.  
  385.  
  386. def EmailFromString(xml_string):
  387.     return CreateClassFromXMLString(Email, xml_string)
  388.  
  389.  
  390. class Uri(AtomBase):
  391.     '''The atom:uri element'''
  392.     _tag = 'uri'
  393.     _namespace = ATOM_NAMESPACE
  394.     _children = AtomBase._children.copy()
  395.     _attributes = AtomBase._attributes.copy()
  396.     
  397.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  398.         '''Constructor for Uri
  399.  
  400.     Args:
  401.       extension_elements: list A  list of ExtensionElement instances
  402.       extension_attributes: dict A dictionary of attribute value string pairs
  403.       text: str The text data in the this element
  404.     '''
  405.         self.text = text
  406.         if not extension_elements:
  407.             pass
  408.         self.extension_elements = []
  409.         if not extension_attributes:
  410.             pass
  411.         self.extension_attributes = { }
  412.  
  413.  
  414.  
  415. def UriFromString(xml_string):
  416.     return CreateClassFromXMLString(Uri, xml_string)
  417.  
  418.  
  419. class Person(AtomBase):
  420.     '''A foundation class from which atom:author and atom:contributor extend.
  421.   
  422.   A person contains information like name, email address, and web page URI for
  423.   an author or contributor to an Atom feed. 
  424.   '''
  425.     _children = AtomBase._children.copy()
  426.     _attributes = AtomBase._attributes.copy()
  427.     _children['{%s}name' % ATOM_NAMESPACE] = ('name', Name)
  428.     _children['{%s}email' % ATOM_NAMESPACE] = ('email', Email)
  429.     _children['{%s}uri' % ATOM_NAMESPACE] = ('uri', Uri)
  430.     
  431.     def __init__(self, name = None, email = None, uri = None, extension_elements = None, extension_attributes = None, text = None):
  432.         """Foundation from which author and contributor are derived.
  433.  
  434.     The constructor is provided for illustrative purposes, you should not
  435.     need to instantiate a Person.
  436.  
  437.     Args:
  438.       name: Name The person's name
  439.       email: Email The person's email address
  440.       uri: Uri The URI of the person's webpage
  441.       extension_elements: list A list of ExtensionElement instances which are
  442.           children of this element.
  443.       extension_attributes: dict A dictionary of strings which are the values
  444.           for additional XML attributes of this element.
  445.       text: String The text contents of the element. This is the contents
  446.           of the Entry's XML text node. (Example: <foo>This is the text</foo>)
  447.     """
  448.         self.name = name
  449.         self.email = email
  450.         self.uri = uri
  451.         if not extension_elements:
  452.             pass
  453.         self.extension_elements = []
  454.         if not extension_attributes:
  455.             pass
  456.         self.extension_attributes = { }
  457.         self.text = text
  458.  
  459.  
  460.  
  461. class Author(Person):
  462.     '''The atom:author element
  463.   
  464.   An author is a required element in Feed. 
  465.   '''
  466.     _tag = 'author'
  467.     _namespace = ATOM_NAMESPACE
  468.     _children = Person._children.copy()
  469.     _attributes = Person._attributes.copy()
  470.     
  471.     def __init__(self, name = None, email = None, uri = None, extension_elements = None, extension_attributes = None, text = None):
  472.         '''Constructor for Author
  473.     
  474.     Args:
  475.       name: Name
  476.       email: Email
  477.       uri: Uri
  478.       extension_elements: list A  list of ExtensionElement instances
  479.       extension_attributes: dict A dictionary of attribute value string pairs
  480.       text: str The text data in the this element
  481.     '''
  482.         self.name = name
  483.         self.email = email
  484.         self.uri = uri
  485.         if not extension_elements:
  486.             pass
  487.         self.extension_elements = []
  488.         if not extension_attributes:
  489.             pass
  490.         self.extension_attributes = { }
  491.         self.text = text
  492.  
  493.  
  494.  
  495. def AuthorFromString(xml_string):
  496.     return CreateClassFromXMLString(Author, xml_string)
  497.  
  498.  
  499. class Contributor(Person):
  500.     '''The atom:contributor element'''
  501.     _tag = 'contributor'
  502.     _namespace = ATOM_NAMESPACE
  503.     _children = Person._children.copy()
  504.     _attributes = Person._attributes.copy()
  505.     
  506.     def __init__(self, name = None, email = None, uri = None, extension_elements = None, extension_attributes = None, text = None):
  507.         '''Constructor for Contributor
  508.     
  509.     Args:
  510.       name: Name
  511.       email: Email
  512.       uri: Uri
  513.       extension_elements: list A  list of ExtensionElement instances
  514.       extension_attributes: dict A dictionary of attribute value string pairs
  515.       text: str The text data in the this element
  516.     '''
  517.         self.name = name
  518.         self.email = email
  519.         self.uri = uri
  520.         if not extension_elements:
  521.             pass
  522.         self.extension_elements = []
  523.         if not extension_attributes:
  524.             pass
  525.         self.extension_attributes = { }
  526.         self.text = text
  527.  
  528.  
  529.  
  530. def ContributorFromString(xml_string):
  531.     return CreateClassFromXMLString(Contributor, xml_string)
  532.  
  533.  
  534. class Link(AtomBase):
  535.     '''The atom:link element'''
  536.     _tag = 'link'
  537.     _namespace = ATOM_NAMESPACE
  538.     _children = AtomBase._children.copy()
  539.     _attributes = AtomBase._attributes.copy()
  540.     _attributes['rel'] = 'rel'
  541.     _attributes['href'] = 'href'
  542.     _attributes['type'] = 'type'
  543.     _attributes['title'] = 'title'
  544.     _attributes['length'] = 'length'
  545.     _attributes['hreflang'] = 'hreflang'
  546.     
  547.     def __init__(self, href = None, rel = None, link_type = None, hreflang = None, title = None, length = None, text = None, extension_elements = None, extension_attributes = None):
  548.         """Constructor for Link
  549.     
  550.     Args:
  551.       href: string The href attribute of the link
  552.       rel: string
  553.       type: string
  554.       hreflang: string The language for the href
  555.       title: string
  556.       length: string The length of the href's destination
  557.       extension_elements: list A  list of ExtensionElement instances
  558.       extension_attributes: dict A dictionary of attribute value string pairs
  559.       text: str The text data in the this element
  560.     """
  561.         self.href = href
  562.         self.rel = rel
  563.         self.type = link_type
  564.         self.hreflang = hreflang
  565.         self.title = title
  566.         self.length = length
  567.         self.text = text
  568.         if not extension_elements:
  569.             pass
  570.         self.extension_elements = []
  571.         if not extension_attributes:
  572.             pass
  573.         self.extension_attributes = { }
  574.  
  575.  
  576.  
  577. def LinkFromString(xml_string):
  578.     return CreateClassFromXMLString(Link, xml_string)
  579.  
  580.  
  581. class Generator(AtomBase):
  582.     '''The atom:generator element'''
  583.     _tag = 'generator'
  584.     _namespace = ATOM_NAMESPACE
  585.     _children = AtomBase._children.copy()
  586.     _attributes = AtomBase._attributes.copy()
  587.     _attributes['uri'] = 'uri'
  588.     _attributes['version'] = 'version'
  589.     
  590.     def __init__(self, uri = None, version = None, text = None, extension_elements = None, extension_attributes = None):
  591.         '''Constructor for Generator
  592.     
  593.     Args:
  594.       uri: string
  595.       version: string
  596.       text: str The text data in the this element
  597.       extension_elements: list A  list of ExtensionElement instances
  598.       extension_attributes: dict A dictionary of attribute value string pairs
  599.     '''
  600.         self.uri = uri
  601.         self.version = version
  602.         self.text = text
  603.         if not extension_elements:
  604.             pass
  605.         self.extension_elements = []
  606.         if not extension_attributes:
  607.             pass
  608.         self.extension_attributes = { }
  609.  
  610.  
  611.  
  612. def GeneratorFromString(xml_string):
  613.     return CreateClassFromXMLString(Generator, xml_string)
  614.  
  615.  
  616. class Text(AtomBase):
  617.     '''A foundation class from which atom:title, summary, etc. extend.
  618.   
  619.   This class should never be instantiated.
  620.   '''
  621.     _children = AtomBase._children.copy()
  622.     _attributes = AtomBase._attributes.copy()
  623.     _attributes['type'] = 'type'
  624.     
  625.     def __init__(self, text_type = None, text = None, extension_elements = None, extension_attributes = None):
  626.         '''Constructor for Text
  627.     
  628.     Args:
  629.       text_type: string
  630.       text: str The text data in the this element
  631.       extension_elements: list A  list of ExtensionElement instances
  632.       extension_attributes: dict A dictionary of attribute value string pairs
  633.     '''
  634.         self.type = text_type
  635.         self.text = text
  636.         if not extension_elements:
  637.             pass
  638.         self.extension_elements = []
  639.         if not extension_attributes:
  640.             pass
  641.         self.extension_attributes = { }
  642.  
  643.  
  644.  
  645. class Title(Text):
  646.     '''The atom:title element'''
  647.     _tag = 'title'
  648.     _namespace = ATOM_NAMESPACE
  649.     _children = Text._children.copy()
  650.     _attributes = Text._attributes.copy()
  651.     
  652.     def __init__(self, title_type = None, text = None, extension_elements = None, extension_attributes = None):
  653.         '''Constructor for Title
  654.     
  655.     Args:
  656.       title_type: string
  657.       text: str The text data in the this element
  658.       extension_elements: list A  list of ExtensionElement instances
  659.       extension_attributes: dict A dictionary of attribute value string pairs
  660.     '''
  661.         self.type = title_type
  662.         self.text = text
  663.         if not extension_elements:
  664.             pass
  665.         self.extension_elements = []
  666.         if not extension_attributes:
  667.             pass
  668.         self.extension_attributes = { }
  669.  
  670.  
  671.  
  672. def TitleFromString(xml_string):
  673.     return CreateClassFromXMLString(Title, xml_string)
  674.  
  675.  
  676. class Subtitle(Text):
  677.     '''The atom:subtitle element'''
  678.     _tag = 'subtitle'
  679.     _namespace = ATOM_NAMESPACE
  680.     _children = Text._children.copy()
  681.     _attributes = Text._attributes.copy()
  682.     
  683.     def __init__(self, subtitle_type = None, text = None, extension_elements = None, extension_attributes = None):
  684.         '''Constructor for Subtitle
  685.     
  686.     Args:
  687.       subtitle_type: string
  688.       text: str The text data in the this element
  689.       extension_elements: list A  list of ExtensionElement instances
  690.       extension_attributes: dict A dictionary of attribute value string pairs
  691.     '''
  692.         self.type = subtitle_type
  693.         self.text = text
  694.         if not extension_elements:
  695.             pass
  696.         self.extension_elements = []
  697.         if not extension_attributes:
  698.             pass
  699.         self.extension_attributes = { }
  700.  
  701.  
  702.  
  703. def SubtitleFromString(xml_string):
  704.     return CreateClassFromXMLString(Subtitle, xml_string)
  705.  
  706.  
  707. class Rights(Text):
  708.     '''The atom:rights element'''
  709.     _tag = 'rights'
  710.     _namespace = ATOM_NAMESPACE
  711.     _children = Text._children.copy()
  712.     _attributes = Text._attributes.copy()
  713.     
  714.     def __init__(self, rights_type = None, text = None, extension_elements = None, extension_attributes = None):
  715.         '''Constructor for Rights
  716.     
  717.     Args:
  718.       rights_type: string
  719.       text: str The text data in the this element
  720.       extension_elements: list A  list of ExtensionElement instances
  721.       extension_attributes: dict A dictionary of attribute value string pairs
  722.     '''
  723.         self.type = rights_type
  724.         self.text = text
  725.         if not extension_elements:
  726.             pass
  727.         self.extension_elements = []
  728.         if not extension_attributes:
  729.             pass
  730.         self.extension_attributes = { }
  731.  
  732.  
  733.  
  734. def RightsFromString(xml_string):
  735.     return CreateClassFromXMLString(Rights, xml_string)
  736.  
  737.  
  738. class Summary(Text):
  739.     '''The atom:summary element'''
  740.     _tag = 'summary'
  741.     _namespace = ATOM_NAMESPACE
  742.     _children = Text._children.copy()
  743.     _attributes = Text._attributes.copy()
  744.     
  745.     def __init__(self, summary_type = None, text = None, extension_elements = None, extension_attributes = None):
  746.         '''Constructor for Summary
  747.     
  748.     Args:
  749.       summary_type: string
  750.       text: str The text data in the this element
  751.       extension_elements: list A  list of ExtensionElement instances
  752.       extension_attributes: dict A dictionary of attribute value string pairs
  753.     '''
  754.         self.type = summary_type
  755.         self.text = text
  756.         if not extension_elements:
  757.             pass
  758.         self.extension_elements = []
  759.         if not extension_attributes:
  760.             pass
  761.         self.extension_attributes = { }
  762.  
  763.  
  764.  
  765. def SummaryFromString(xml_string):
  766.     return CreateClassFromXMLString(Summary, xml_string)
  767.  
  768.  
  769. class Content(Text):
  770.     '''The atom:content element'''
  771.     _tag = 'content'
  772.     _namespace = ATOM_NAMESPACE
  773.     _children = Text._children.copy()
  774.     _attributes = Text._attributes.copy()
  775.     _attributes['src'] = 'src'
  776.     
  777.     def __init__(self, content_type = None, src = None, text = None, extension_elements = None, extension_attributes = None):
  778.         '''Constructor for Content
  779.     
  780.     Args:
  781.       content_type: string
  782.       src: string
  783.       text: str The text data in the this element
  784.       extension_elements: list A  list of ExtensionElement instances
  785.       extension_attributes: dict A dictionary of attribute value string pairs
  786.     '''
  787.         self.type = content_type
  788.         self.src = src
  789.         self.text = text
  790.         if not extension_elements:
  791.             pass
  792.         self.extension_elements = []
  793.         if not extension_attributes:
  794.             pass
  795.         self.extension_attributes = { }
  796.  
  797.  
  798.  
  799. def ContentFromString(xml_string):
  800.     return CreateClassFromXMLString(Content, xml_string)
  801.  
  802.  
  803. class Category(AtomBase):
  804.     '''The atom:category element'''
  805.     _tag = 'category'
  806.     _namespace = ATOM_NAMESPACE
  807.     _children = AtomBase._children.copy()
  808.     _attributes = AtomBase._attributes.copy()
  809.     _attributes['term'] = 'term'
  810.     _attributes['scheme'] = 'scheme'
  811.     _attributes['label'] = 'label'
  812.     
  813.     def __init__(self, term = None, scheme = None, label = None, text = None, extension_elements = None, extension_attributes = None):
  814.         '''Constructor for Category
  815.     
  816.     Args:
  817.       term: str
  818.       scheme: str
  819.       label: str
  820.       text: str The text data in the this element
  821.       extension_elements: list A  list of ExtensionElement instances
  822.       extension_attributes: dict A dictionary of attribute value string pairs
  823.     '''
  824.         self.term = term
  825.         self.scheme = scheme
  826.         self.label = label
  827.         self.text = text
  828.         if not extension_elements:
  829.             pass
  830.         self.extension_elements = []
  831.         if not extension_attributes:
  832.             pass
  833.         self.extension_attributes = { }
  834.  
  835.  
  836.  
  837. def CategoryFromString(xml_string):
  838.     return CreateClassFromXMLString(Category, xml_string)
  839.  
  840.  
  841. class Id(AtomBase):
  842.     '''The atom:id element.'''
  843.     _tag = 'id'
  844.     _namespace = ATOM_NAMESPACE
  845.     _children = AtomBase._children.copy()
  846.     _attributes = AtomBase._attributes.copy()
  847.     
  848.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  849.         '''Constructor for Id
  850.     
  851.     Args:
  852.       text: str The text data in the this element
  853.       extension_elements: list A  list of ExtensionElement instances
  854.       extension_attributes: dict A dictionary of attribute value string pairs
  855.     '''
  856.         self.text = text
  857.         if not extension_elements:
  858.             pass
  859.         self.extension_elements = []
  860.         if not extension_attributes:
  861.             pass
  862.         self.extension_attributes = { }
  863.  
  864.  
  865.  
  866. def IdFromString(xml_string):
  867.     return CreateClassFromXMLString(Id, xml_string)
  868.  
  869.  
  870. class Icon(AtomBase):
  871.     '''The atom:icon element.'''
  872.     _tag = 'icon'
  873.     _namespace = ATOM_NAMESPACE
  874.     _children = AtomBase._children.copy()
  875.     _attributes = AtomBase._attributes.copy()
  876.     
  877.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  878.         '''Constructor for Icon
  879.     
  880.     Args:
  881.       text: str The text data in the this element
  882.       extension_elements: list A  list of ExtensionElement instances
  883.       extension_attributes: dict A dictionary of attribute value string pairs
  884.     '''
  885.         self.text = text
  886.         if not extension_elements:
  887.             pass
  888.         self.extension_elements = []
  889.         if not extension_attributes:
  890.             pass
  891.         self.extension_attributes = { }
  892.  
  893.  
  894.  
  895. def IconFromString(xml_string):
  896.     return CreateClassFromXMLString(Icon, xml_string)
  897.  
  898.  
  899. class Logo(AtomBase):
  900.     '''The atom:logo element.'''
  901.     _tag = 'logo'
  902.     _namespace = ATOM_NAMESPACE
  903.     _children = AtomBase._children.copy()
  904.     _attributes = AtomBase._attributes.copy()
  905.     
  906.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  907.         '''Constructor for Logo
  908.     
  909.     Args:
  910.       text: str The text data in the this element
  911.       extension_elements: list A  list of ExtensionElement instances
  912.       extension_attributes: dict A dictionary of attribute value string pairs
  913.     '''
  914.         self.text = text
  915.         if not extension_elements:
  916.             pass
  917.         self.extension_elements = []
  918.         if not extension_attributes:
  919.             pass
  920.         self.extension_attributes = { }
  921.  
  922.  
  923.  
  924. def LogoFromString(xml_string):
  925.     return CreateClassFromXMLString(Logo, xml_string)
  926.  
  927.  
  928. class Draft(AtomBase):
  929.     '''The app:draft element which indicates if this entry should be public.'''
  930.     _tag = 'draft'
  931.     _namespace = APP_NAMESPACE
  932.     _children = AtomBase._children.copy()
  933.     _attributes = AtomBase._attributes.copy()
  934.     
  935.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  936.         '''Constructor for app:draft
  937.  
  938.     Args:
  939.       text: str The text data in the this element
  940.       extension_elements: list A  list of ExtensionElement instances
  941.       extension_attributes: dict A dictionary of attribute value string pairs
  942.     '''
  943.         self.text = text
  944.         if not extension_elements:
  945.             pass
  946.         self.extension_elements = []
  947.         if not extension_attributes:
  948.             pass
  949.         self.extension_attributes = { }
  950.  
  951.  
  952.  
  953. def DraftFromString(xml_string):
  954.     return CreateClassFromXMLString(Draft, xml_string)
  955.  
  956.  
  957. class Control(AtomBase):
  958.     '''The app:control element indicating restrictions on publication.
  959.   
  960.   The APP control element may contain a draft element indicating whether or
  961.   not this entry should be publicly available.
  962.   '''
  963.     _tag = 'control'
  964.     _namespace = APP_NAMESPACE
  965.     _children = AtomBase._children.copy()
  966.     _attributes = AtomBase._attributes.copy()
  967.     _children['{%s}draft' % APP_NAMESPACE] = ('draft', Draft)
  968.     
  969.     def __init__(self, draft = None, text = None, extension_elements = None, extension_attributes = None):
  970.         '''Constructor for app:control'''
  971.         self.draft = draft
  972.         self.text = text
  973.         if not extension_elements:
  974.             pass
  975.         self.extension_elements = []
  976.         if not extension_attributes:
  977.             pass
  978.         self.extension_attributes = { }
  979.  
  980.  
  981.  
  982. def ControlFromString(xml_string):
  983.     return CreateClassFromXMLString(Control, xml_string)
  984.  
  985.  
  986. class Date(AtomBase):
  987.     '''A parent class for atom:updated, published, etc.'''
  988.     _children = AtomBase._children.copy()
  989.     _attributes = AtomBase._attributes.copy()
  990.     
  991.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  992.         self.text = text
  993.         if not extension_elements:
  994.             pass
  995.         self.extension_elements = []
  996.         if not extension_attributes:
  997.             pass
  998.         self.extension_attributes = { }
  999.  
  1000.  
  1001.  
  1002. class Updated(Date):
  1003.     '''The atom:updated element.'''
  1004.     _tag = 'updated'
  1005.     _namespace = ATOM_NAMESPACE
  1006.     _children = Date._children.copy()
  1007.     _attributes = Date._attributes.copy()
  1008.     
  1009.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  1010.         '''Constructor for Updated
  1011.     
  1012.     Args:
  1013.       text: str The text data in the this element
  1014.       extension_elements: list A  list of ExtensionElement instances
  1015.       extension_attributes: dict A dictionary of attribute value string pairs
  1016.     '''
  1017.         self.text = text
  1018.         if not extension_elements:
  1019.             pass
  1020.         self.extension_elements = []
  1021.         if not extension_attributes:
  1022.             pass
  1023.         self.extension_attributes = { }
  1024.  
  1025.  
  1026.  
  1027. def UpdatedFromString(xml_string):
  1028.     return CreateClassFromXMLString(Updated, xml_string)
  1029.  
  1030.  
  1031. class Published(Date):
  1032.     '''The atom:published element.'''
  1033.     _tag = 'published'
  1034.     _namespace = ATOM_NAMESPACE
  1035.     _children = Date._children.copy()
  1036.     _attributes = Date._attributes.copy()
  1037.     
  1038.     def __init__(self, text = None, extension_elements = None, extension_attributes = None):
  1039.         '''Constructor for Published
  1040.     
  1041.     Args:
  1042.       text: str The text data in the this element
  1043.       extension_elements: list A  list of ExtensionElement instances
  1044.       extension_attributes: dict A dictionary of attribute value string pairs
  1045.     '''
  1046.         self.text = text
  1047.         if not extension_elements:
  1048.             pass
  1049.         self.extension_elements = []
  1050.         if not extension_attributes:
  1051.             pass
  1052.         self.extension_attributes = { }
  1053.  
  1054.  
  1055.  
  1056. def PublishedFromString(xml_string):
  1057.     return CreateClassFromXMLString(Published, xml_string)
  1058.  
  1059.  
  1060. class LinkFinder(object):
  1061.     '''An "interface" providing methods to find link elements
  1062.  
  1063.   Entry elements often contain multiple links which differ in the rel
  1064.   attribute or content type. Often, developers are interested in a specific
  1065.   type of link so this class provides methods to find specific classes of
  1066.   links.
  1067.  
  1068.   This class is used as a mixin in Atom entries and feeds.
  1069.   '''
  1070.     
  1071.     def GetSelfLink(self):
  1072.         """Find the first link with rel set to 'self'
  1073.  
  1074.     Returns:
  1075.       An atom.Link or none if none of the links had rel equal to 'self'
  1076.     """
  1077.         for a_link in self.link:
  1078.             if a_link.rel == 'self':
  1079.                 return a_link
  1080.         
  1081.  
  1082.     
  1083.     def GetEditLink(self):
  1084.         for a_link in self.link:
  1085.             if a_link.rel == 'edit':
  1086.                 return a_link
  1087.         
  1088.  
  1089.     
  1090.     def GetNextLink(self):
  1091.         for a_link in self.link:
  1092.             if a_link.rel == 'next':
  1093.                 return a_link
  1094.         
  1095.  
  1096.     
  1097.     def GetLicenseLink(self):
  1098.         for a_link in self.link:
  1099.             if a_link.rel == 'license':
  1100.                 return a_link
  1101.         
  1102.  
  1103.     
  1104.     def GetAlternateLink(self):
  1105.         for a_link in self.link:
  1106.             if a_link.rel == 'alternate':
  1107.                 return a_link
  1108.         
  1109.  
  1110.  
  1111.  
  1112. class FeedEntryParent(AtomBase, LinkFinder):
  1113.     '''A super class for atom:feed and entry, contains shared attributes'''
  1114.     _children = AtomBase._children.copy()
  1115.     _attributes = AtomBase._attributes.copy()
  1116.     _children['{%s}author' % ATOM_NAMESPACE] = ('author', [
  1117.         Author])
  1118.     _children['{%s}category' % ATOM_NAMESPACE] = ('category', [
  1119.         Category])
  1120.     _children['{%s}contributor' % ATOM_NAMESPACE] = ('contributor', [
  1121.         Contributor])
  1122.     _children['{%s}id' % ATOM_NAMESPACE] = ('id', Id)
  1123.     _children['{%s}link' % ATOM_NAMESPACE] = ('link', [
  1124.         Link])
  1125.     _children['{%s}rights' % ATOM_NAMESPACE] = ('rights', Rights)
  1126.     _children['{%s}title' % ATOM_NAMESPACE] = ('title', Title)
  1127.     _children['{%s}updated' % ATOM_NAMESPACE] = ('updated', Updated)
  1128.     
  1129.     def __init__(self, author = None, category = None, contributor = None, atom_id = None, link = None, rights = None, title = None, updated = None, text = None, extension_elements = None, extension_attributes = None):
  1130.         if not author:
  1131.             pass
  1132.         self.author = []
  1133.         if not category:
  1134.             pass
  1135.         self.category = []
  1136.         if not contributor:
  1137.             pass
  1138.         self.contributor = []
  1139.         self.id = atom_id
  1140.         if not link:
  1141.             pass
  1142.         self.link = []
  1143.         self.rights = rights
  1144.         self.title = title
  1145.         self.updated = updated
  1146.         self.text = text
  1147.         if not extension_elements:
  1148.             pass
  1149.         self.extension_elements = []
  1150.         if not extension_attributes:
  1151.             pass
  1152.         self.extension_attributes = { }
  1153.  
  1154.  
  1155.  
  1156. class Source(FeedEntryParent):
  1157.     '''The atom:source element'''
  1158.     _tag = 'source'
  1159.     _namespace = ATOM_NAMESPACE
  1160.     _children = FeedEntryParent._children.copy()
  1161.     _attributes = FeedEntryParent._attributes.copy()
  1162.     _children['{%s}generator' % ATOM_NAMESPACE] = ('generator', Generator)
  1163.     _children['{%s}icon' % ATOM_NAMESPACE] = ('icon', Icon)
  1164.     _children['{%s}logo' % ATOM_NAMESPACE] = ('logo', Logo)
  1165.     _children['{%s}subtitle' % ATOM_NAMESPACE] = ('subtitle', Subtitle)
  1166.     
  1167.     def __init__(self, author = None, category = None, contributor = None, generator = None, icon = None, atom_id = None, link = None, logo = None, rights = None, subtitle = None, title = None, updated = None, text = None, extension_elements = None, extension_attributes = None):
  1168.         """Constructor for Source
  1169.  
  1170.     Args:
  1171.       author: list (optional) A list of Author instances which belong to this
  1172.           class.
  1173.       category: list (optional) A list of Category instances
  1174.       contributor: list (optional) A list on Contributor instances
  1175.       generator: Generator (optional)
  1176.       icon: Icon (optional)
  1177.       id: Id (optional) The entry's Id element
  1178.       link: list (optional) A list of Link instances
  1179.       logo: Logo (optional)
  1180.       rights: Rights (optional) The entry's Rights element
  1181.       subtitle: Subtitle (optional) The entry's subtitle element
  1182.       title: Title (optional) the entry's title element
  1183.       updated: Updated (optional) the entry's updated element
  1184.       text: String (optional) The text contents of the element. This is the
  1185.           contents of the Entry's XML text node.
  1186.           (Example: <foo>This is the text</foo>)
  1187.       extension_elements: list (optional) A list of ExtensionElement instances
  1188.           which are children of this element.
  1189.       extension_attributes: dict (optional) A dictionary of strings which are
  1190.           the values for additional XML attributes of this element.
  1191.     """
  1192.         if not author:
  1193.             pass
  1194.         self.author = []
  1195.         if not category:
  1196.             pass
  1197.         self.category = []
  1198.         if not contributor:
  1199.             pass
  1200.         self.contributor = []
  1201.         self.generator = generator
  1202.         self.icon = icon
  1203.         self.id = atom_id
  1204.         if not link:
  1205.             pass
  1206.         self.link = []
  1207.         self.logo = logo
  1208.         self.rights = rights
  1209.         self.subtitle = subtitle
  1210.         self.title = title
  1211.         self.updated = updated
  1212.         self.text = text
  1213.         if not extension_elements:
  1214.             pass
  1215.         self.extension_elements = []
  1216.         if not extension_attributes:
  1217.             pass
  1218.         self.extension_attributes = { }
  1219.  
  1220.  
  1221.  
  1222. def SourceFromString(xml_string):
  1223.     return CreateClassFromXMLString(Source, xml_string)
  1224.  
  1225.  
  1226. class Entry(FeedEntryParent):
  1227.     '''The atom:entry element'''
  1228.     _tag = 'entry'
  1229.     _namespace = ATOM_NAMESPACE
  1230.     _children = FeedEntryParent._children.copy()
  1231.     _attributes = FeedEntryParent._attributes.copy()
  1232.     _children['{%s}content' % ATOM_NAMESPACE] = ('content', Content)
  1233.     _children['{%s}published' % ATOM_NAMESPACE] = ('published', Published)
  1234.     _children['{%s}source' % ATOM_NAMESPACE] = ('source', Source)
  1235.     _children['{%s}summary' % ATOM_NAMESPACE] = ('summary', Summary)
  1236.     _children['{%s}control' % APP_NAMESPACE] = ('control', Control)
  1237.     
  1238.     def __init__(self, author = None, category = None, content = None, contributor = None, atom_id = None, link = None, published = None, rights = None, source = None, summary = None, control = None, title = None, updated = None, extension_elements = None, extension_attributes = None, text = None):
  1239.         """Constructor for atom:entry
  1240.  
  1241.     Args:
  1242.       author: list A list of Author instances which belong to this class.
  1243.       category: list A list of Category instances
  1244.       content: Content The entry's Content
  1245.       contributor: list A list on Contributor instances
  1246.       id: Id The entry's Id element
  1247.       link: list A list of Link instances
  1248.       published: Published The entry's Published element
  1249.       rights: Rights The entry's Rights element
  1250.       source: Source the entry's source element
  1251.       summary: Summary the entry's summary element
  1252.       title: Title the entry's title element
  1253.       updated: Updated the entry's updated element
  1254.       control: The entry's app:control element which can be used to mark an 
  1255.           entry as a draft which should not be publicly viewable.
  1256.       text: String The text contents of the element. This is the contents
  1257.           of the Entry's XML text node. (Example: <foo>This is the text</foo>)
  1258.       extension_elements: list A list of ExtensionElement instances which are
  1259.           children of this element.
  1260.       extension_attributes: dict A dictionary of strings which are the values
  1261.           for additional XML attributes of this element.
  1262.     """
  1263.         if not author:
  1264.             pass
  1265.         self.author = []
  1266.         if not category:
  1267.             pass
  1268.         self.category = []
  1269.         self.content = content
  1270.         if not contributor:
  1271.             pass
  1272.         self.contributor = []
  1273.         self.id = atom_id
  1274.         if not link:
  1275.             pass
  1276.         self.link = []
  1277.         self.published = published
  1278.         self.rights = rights
  1279.         self.source = source
  1280.         self.summary = summary
  1281.         self.title = title
  1282.         self.updated = updated
  1283.         self.control = control
  1284.         self.text = text
  1285.         if not extension_elements:
  1286.             pass
  1287.         self.extension_elements = []
  1288.         if not extension_attributes:
  1289.             pass
  1290.         self.extension_attributes = { }
  1291.  
  1292.  
  1293.  
  1294. def EntryFromString(xml_string):
  1295.     return CreateClassFromXMLString(Entry, xml_string)
  1296.  
  1297.  
  1298. class Feed(Source):
  1299.     '''The atom:feed element'''
  1300.     _tag = 'feed'
  1301.     _namespace = ATOM_NAMESPACE
  1302.     _children = Source._children.copy()
  1303.     _attributes = Source._attributes.copy()
  1304.     _children['{%s}entry' % ATOM_NAMESPACE] = ('entry', [
  1305.         Entry])
  1306.     
  1307.     def __init__(self, author = None, category = None, contributor = None, generator = None, icon = None, atom_id = None, link = None, logo = None, rights = None, subtitle = None, title = None, updated = None, entry = None, text = None, extension_elements = None, extension_attributes = None):
  1308.         """Constructor for Source
  1309.     
  1310.     Args:
  1311.       author: list (optional) A list of Author instances which belong to this
  1312.           class.
  1313.       category: list (optional) A list of Category instances
  1314.       contributor: list (optional) A list on Contributor instances
  1315.       generator: Generator (optional) 
  1316.       icon: Icon (optional) 
  1317.       id: Id (optional) The entry's Id element
  1318.       link: list (optional) A list of Link instances
  1319.       logo: Logo (optional) 
  1320.       rights: Rights (optional) The entry's Rights element
  1321.       subtitle: Subtitle (optional) The entry's subtitle element
  1322.       title: Title (optional) the entry's title element
  1323.       updated: Updated (optional) the entry's updated element
  1324.       entry: list (optional) A list of the Entry instances contained in the 
  1325.           feed.
  1326.       text: String (optional) The text contents of the element. This is the 
  1327.           contents of the Entry's XML text node. 
  1328.           (Example: <foo>This is the text</foo>)
  1329.       extension_elements: list (optional) A list of ExtensionElement instances
  1330.           which are children of this element.
  1331.       extension_attributes: dict (optional) A dictionary of strings which are 
  1332.           the values for additional XML attributes of this element.
  1333.     """
  1334.         if not author:
  1335.             pass
  1336.         self.author = []
  1337.         if not category:
  1338.             pass
  1339.         self.category = []
  1340.         if not contributor:
  1341.             pass
  1342.         self.contributor = []
  1343.         self.generator = generator
  1344.         self.icon = icon
  1345.         self.id = atom_id
  1346.         if not link:
  1347.             pass
  1348.         self.link = []
  1349.         self.logo = logo
  1350.         self.rights = rights
  1351.         self.subtitle = subtitle
  1352.         self.title = title
  1353.         self.updated = updated
  1354.         if not entry:
  1355.             pass
  1356.         self.entry = []
  1357.         self.text = text
  1358.         if not extension_elements:
  1359.             pass
  1360.         self.extension_elements = []
  1361.         if not extension_attributes:
  1362.             pass
  1363.         self.extension_attributes = { }
  1364.  
  1365.  
  1366.  
  1367. def FeedFromString(xml_string):
  1368.     return CreateClassFromXMLString(Feed, xml_string)
  1369.  
  1370.  
  1371. class ExtensionElement(object):
  1372.     '''Represents extra XML elements contained in Atom classes.'''
  1373.     
  1374.     def __init__(self, tag, namespace = None, attributes = None, children = None, text = None):
  1375.         '''Constructor for EtensionElement
  1376.  
  1377.     Args:
  1378.       namespace: string (optional) The XML namespace for this element.
  1379.       tag: string (optional) The tag (without the namespace qualifier) for
  1380.           this element. To reconstruct the full qualified name of the element,
  1381.           combine this tag with the namespace.
  1382.       attributes: dict (optinal) The attribute value string pairs for the XML 
  1383.           attributes of this element.
  1384.       children: list (optional) A list of ExtensionElements which represent 
  1385.           the XML child nodes of this element.
  1386.     '''
  1387.         self.namespace = namespace
  1388.         self.tag = tag
  1389.         if not attributes:
  1390.             pass
  1391.         self.attributes = { }
  1392.         if not children:
  1393.             pass
  1394.         self.children = []
  1395.         self.text = text
  1396.  
  1397.     
  1398.     def ToString(self):
  1399.         element_tree = self._TransferToElementTree(ElementTree.Element(''))
  1400.         return ElementTree.tostring(element_tree, encoding = 'UTF-8')
  1401.  
  1402.     
  1403.     def _TransferToElementTree(self, element_tree):
  1404.         if self.tag is None:
  1405.             return None
  1406.         if self.namespace is not None:
  1407.             element_tree.tag = '{%s}%s' % (self.namespace, self.tag)
  1408.         else:
  1409.             element_tree.tag = self.tag
  1410.         for key, value in self.attributes.iteritems():
  1411.             element_tree.attrib[key] = value
  1412.         
  1413.         for child in self.children:
  1414.             child._BecomeChildElement(element_tree)
  1415.         
  1416.         element_tree.text = self.text
  1417.         return element_tree
  1418.  
  1419.     
  1420.     def _BecomeChildElement(self, element_tree):
  1421.         """Converts this object into an etree element and adds it as a child node.
  1422.  
  1423.     Adds self to the ElementTree. This method is required to avoid verbose XML
  1424.     which constantly redefines the namespace.
  1425.  
  1426.     Args:
  1427.       element_tree: ElementTree._Element The element to which this object's XML
  1428.           will be added.
  1429.     """
  1430.         new_element = ElementTree.Element('')
  1431.         element_tree.append(new_element)
  1432.         self._TransferToElementTree(new_element)
  1433.  
  1434.     
  1435.     def FindChildren(self, tag = None, namespace = None):
  1436.         '''Searches child nodes for objects with the desired tag/namespace.
  1437.  
  1438.     Returns a list of extension elements within this object whose tag
  1439.     and/or namespace match those passed in. To find all children in
  1440.     a particular namespace, specify the namespace but not the tag name.
  1441.     If you specify only the tag, the result list may contain extension
  1442.     elements in multiple namespaces.
  1443.  
  1444.     Args:
  1445.       tag: str (optional) The desired tag
  1446.       namespace: str (optional) The desired namespace
  1447.  
  1448.     Returns:
  1449.       A list of elements whose tag and/or namespace match the parameters
  1450.       values
  1451.     '''
  1452.         results = []
  1453.         if tag and namespace:
  1454.             for element in self.children:
  1455.                 if element.tag == tag and element.namespace == namespace:
  1456.                     results.append(element)
  1457.                     continue
  1458.             
  1459.         elif tag and not namespace:
  1460.             for element in self.children:
  1461.                 if element.tag == tag:
  1462.                     results.append(element)
  1463.                     continue
  1464.             
  1465.         elif namespace and not tag:
  1466.             for element in self.children:
  1467.                 if element.namespace == namespace:
  1468.                     results.append(element)
  1469.                     continue
  1470.             
  1471.         else:
  1472.             for element in self.children:
  1473.                 results.append(element)
  1474.             
  1475.         return results
  1476.  
  1477.  
  1478.  
  1479. def ExtensionElementFromString(xml_string):
  1480.     element_tree = ElementTree.fromstring(xml_string)
  1481.     return _ExtensionElementFromElementTree(element_tree)
  1482.  
  1483.  
  1484. def _ExtensionElementFromElementTree(element_tree):
  1485.     element_tag = element_tree.tag
  1486.     if '}' in element_tag:
  1487.         namespace = element_tag[1:element_tag.index('}')]
  1488.         tag = element_tag[element_tag.index('}') + 1:]
  1489.     else:
  1490.         namespace = None
  1491.         tag = element_tag
  1492.     extension = ExtensionElement(namespace = namespace, tag = tag)
  1493.     for key, value in element_tree.attrib.iteritems():
  1494.         extension.attributes[key] = value
  1495.     
  1496.     for child in element_tree:
  1497.         extension.children.append(_ExtensionElementFromElementTree(child))
  1498.     
  1499.     extension.text = element_tree.text
  1500.     return extension
  1501.  
  1502.